11110 - Equidivisions (DFS, maratón colombiana) &&
[and.git] / 10452 - Marcus, help / 10452.cpp
blobe11f4588d6db1cd9ebbbc3aa7047cb4c657a7de7
1 #include <iostream>
2 #include <string>
4 using namespace std;
6 int di[] = { 0, -1, 0};
7 int dj[] = { -1, 0, 1};
8 string dir[] = {"left", "forth", "right"};
10 char g[9][9];
12 string route = "@IEHOVA#";
15 int main(){
16 int n;
17 cin >> n;
18 while (n--){
19 pair<int,int> start;
20 int r, c;
21 cin >> r >> c;
22 for (int i=0; i<r; ++i){
23 for (int j=0; j<c; ++j){
24 cin >> g[i][j];
25 if (g[i][j] == '@') start = make_pair(i,j);
29 int i = start. first;
30 int j = start.second;
31 string res = "";
32 for (int k = 1; k < 8; ++k){
33 for (int l = 0; l < 3; ++l){
34 int ni = i + di[l];
35 int nj = j + dj[l];
36 if (0 <= ni && ni < r && 0 <= nj && nj < c &&
37 g[ni][nj] == route[k]){
38 res += dir[l];
39 res += (k<7?" ":"");
40 i = ni;
41 j = nj;
42 break;
46 cout << res << endl;
48 return 0;